# models/download_file.py - 下载文件模型
from typing import Dict, Any
from datetime import datetime

class DownloadFile:
    """下载文件基础信息模型"""
    
    def __init__(self, name: str, brief: str = "", description: str = "", 
                 preview_image: str = "preview.png"):
        self.name = name
        self.brief = brief
        self.description = description
        self.preview_image = preview_image
        self.created_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        self.updated_time = self.created_time
    
    def to_dict(self) -> Dict[str, Any]:
        """转换为字典"""
        return {
            "name": self.name,
            "brief": self.brief,
            "description": self.description,
            "preview_image": self.preview_image,
            "created_time": self.created_time,
            "updated_time": self.updated_time
        }
    
    @classmethod
    def from_dict(cls, data: Dict[str, Any]) -> 'DownloadFile':
        """从字典创建实例"""
        instance = cls(
            name=data.get("name", ""),
            brief=data.get("brief", ""),
            description=data.get("description", ""),
            preview_image=data.get("preview_image", "preview.png")
        )
        instance.created_time = data.get("created_time", instance.created_time)
        instance.updated_time = data.get("updated_time", instance.updated_time)
        return instance